# need auto_validation off to render non-XHTML XML
Markaby::Builder.set(:auto_validation, false)
Markaby::Builder.set(:indent, 2)

module Fluxr::Views
  module XML
    def layout
      fluxr_response_xml {yield}
    end
    
    def workflow_create
      tag!("result") { "success" }
      tag!("fei") { @fei }
      tag!("wfid") { @fei.wfid }
      text(@fei.methods.inspect)
    end
    
    def workflow_status
      workflow_status_xml(@s)
    end
    
    def workflow_list
      tag!("workflow-list") do 
        @ss.each do |wfid, s|
          workflow_status_xml(s)
        end
      end
    end
    
    def workflow_update
      tag!("result") { "success" }
      tag!("workflow-update") do
        workitem_xml(@workitem)
      end
    end
    
    def workflow_destroy
      tag!("result") { "success" }
    end
    
    def participant_list
      tag!("participants") do
        @participant_map.participants.each do |p|
          participant_xml(p)
        end
      end
    end
    
    def error
      tag!("error") do
        tag!("message") { @message }
        tag!("wfid") { @id }
      end
    end
  end
  default_format :XML
  
  
  module HTML
    def test
      p @workflows.collect{|w| w.class}.inspect
      hr 
      form :method => 'get', :action => '/workflows' do
        p "read"
        input :type => 'hidden', :name => '_method', :value => 'get'
        select :name => 'id' do
          @workflows.each do |w|
            option(:value => w.environment_id.wfid) { w.environment_id.wfid }
          end
        end
        button(:type => 'submit') {"submit"}
      end
      hr
      
      form :method => 'get', :action => '/workflows' do
        p "list"
        input :type => 'hidden', :name => '_method', :value => 'get'
        button(:type => 'submit') {"submit"}
      end
      hr
      
      form :method => 'post', :action => '/workflows' do
        p "create"
        input :type => 'hidden', :name => '_method', :value => 'post'
        input :type => 'text', :name => 'workflow_definition', :size => 40
        button(:type => 'submit') {"submit"}
      end
      hr
      
      form :method => 'post', :action => '/workflows' do
        p "destroy"
        select :name => 'id' do
          @workflows.each do |w|
            option(:value => w.environment_id.wfid) { w.environment_id.wfid }
          end
        end
        input :type => 'hidden', :name => '_method', :value => 'delete'
        button(:type => 'submit') {"submit"}
      end
      hr
      
      form :method => 'post', :action => '/workflows' do
        p "update"
        input :type => 'hidden', :name => '_method', :value => 'put'
        input :type => 'text', :name => 'participant'
        input :type => 'text', :name => 'data[name]'
        select :name => 'id' do
          @workflows.each do |w|
            option(:value => w.environment_id.wfid) { w.environment_id.wfid }
          end
        end
        button(:type => 'submit') {"submit"}
      end
    end
  end
 
end
